﻿$(document).ready(function () {
    $('#xzqhgrid').treegrid({
        title: "行政区划",
        idField: 'XZQDM',
        treeField: 'XZQMC',
        columns: [[
            { field: 'XZQMC', title: '行政区名称', width: 160 },
            { field: 'XZQDM', title: '行政区代码', width: 100 },
            { field: 'BZ', title: '备注', width: 80 }
        ]],
        onBeforeExpand: function (row) {
            if (row.XZQDM.substring(2, 6) == "0000") {
                var childs = $('#xzqhgrid').treegrid('getChildren', row.XZQDM);
                if (childs != null && childs.length == 0) {
                    GetSmJSON(CLDJServiceUrl + "/SmwsFrame.asmx/GetXZQTreeGrid2", "{'xzqdm':'"+row.XZQDM+"'}", function (d) {
                        if (d != "") {
                            $('#xzqhgrid').treegrid('append', {
                                parent: row.XZQDM,  // the node has a 'id' value that defined through 'idField' property
                                data: JSON.parse(d)
                            });
                        }
                    });
                }
            }
        }
    });

    reloadgrid();

    function reloadgrid() {
        GetSmJSON(CLDJServiceUrl + "/SmwsFrame.asmx/GetXZQTreeGrid1", "{}", function (d) {
            if (d != "") {
                $('#xzqhgrid').treegrid('loadData', JSON.parse(d));
            }
        });
    }

});